package com.momo.forword.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.momo.common.core.request.PageParams;
import com.momo.common.core.result.Rs;
import com.momo.upms.api.UserApi;
import com.momo.upms.condition.UserCondition;
import com.momo.upms.dto.UserDTO;
import com.momo.upms.vo.UserVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
@Api(value = "用户相关接口", tags = "用户相关接口")
public class UserController {

    @Autowired
    private UserApi userApi;

    @PostMapping("/page")
    public Rs<Page<UserVO>> page(@RequestBody PageParams<UserCondition> userCondition){
        Object principal1 = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println(principal1);
        return userApi.pageUser(userCondition);
    }

    @PostMapping("/insert")
    public Rs<UserVO> insertUser(@RequestBody UserDTO userDTO){
        return userApi.insertUser(userDTO);
    }

    @PostMapping("/update")
    public Rs<UserVO> updateUser(@RequestBody UserDTO userDTO){
        return userApi.updateUser(userDTO);
    }

    @GetMapping("/get/{id}")
    public Rs<UserVO> getUser(@PathVariable("id") Long userId){
        return userApi.getUser(userId);
    }

    @PostMapping("/delete/{id}")
    public Rs<Boolean> deleteUser(@PathVariable("id") Long userId){
        return userApi.deleteUser(userId);
    }

}
